Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core.remove_detached_inventory #7684

Merged
merged 4 commits into from Oct 10, 2018

Conversation

SmallJoker
Copy link
Member

@SmallJoker SmallJoker commented Aug 29, 2018

Adds the possibility to remove detached inventories after initialization.
This PR will also drop the backwards compatibility to make proper use of the NetworkPacket operators.

Test code

core.register_on_joinplayer(function(player)
	-- Init public and restricted inventory
	local inv_all = core.create_detached_inventory("foobar_all", {
		allow_put = function() print("put all?") return 1 end
	})
	inv_all:set_size("bazz1", 4)
	local inv_me = core.create_detached_inventory("foobar_me", {
		allow_put = function() print("put me?") return 1 end
		
	}, "singleplayer")
	inv_me:set_size("bazz2", 4)

	core.show_formspec(player:get_player_name(), "test", [[
		size[4,5]
		list[detached:foobar_all;bazz1;0,0;4,1]
		list[detached:foobar_me;bazz2;0,2;4,1]
		list[current_player;main;0,4;4,1]
	]])

	-- Check whether the deletion works correctly
	core.after(8, function()
		core.remove_detached_inventory("foobar_all")
	end)
	core.after(12, function()
		core.remove_detached_inventory("foobar_me")
	end)
end)

@SmallJoker SmallJoker added Protocol bump @ Network Feature ✨ PRs that add or enhance a feature labels Aug 29, 2018
@sfan5 sfan5 self-requested a review August 29, 2018 19:06
src/server.cpp Outdated
inv->serialize(os);
if (player_it == m_detached_inventories_player.end() ||
player_it->second.empty()) {
// ok. no restriction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wouldn't call these "restrictions"

		// Send to everyone

src/server.cpp Outdated
// Make data buffer
std::string s = os.str();
if (peer_id != PEER_ID_INEXISTENT && peer_id != p->getPeerId())
return; // Send to nobody
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is hard to grasp on first sight

			return; // Caller requested send to a different player, so don't send.

@SmallJoker SmallJoker merged commit 0a5e771 into minetest:master Oct 10, 2018
@SmallJoker SmallJoker deleted the delete_detached branch November 28, 2018 19:13
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 23, 2019
Breaks backwards compatibility for good
Bump protocol version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants